//
//  Team9homeTableViewCell.m
//  Team9Project
//
//  Created by dlios on 15/10/13.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9homeTableViewCell.h"
#import "Team9HomeModel.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>

@implementation Team9homeTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}


- (void)setHomeModel:(Team9HomeModel *)homeModel{
    if (_homeModel != homeModel) {
        _homeModel = homeModel;
    
    }

    self.likeImageView.image = [UIImage imageNamed:@"like"];
    
    [self.faceImageView sd_setImageWithURL:[NSURL URLWithString:_homeModel.author_face] placeholderImage:[UIImage imageNamed:@"333"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        [UIView animateWithDuration:0.3 animations:^{
            CATransition *transition = [CATransition animation];
            transition.type = @"fade";
            [transition setDuration:0.5];
            [transition setRepeatCount:1];
            // 向imageView上添加动画效果
            [self.faceImageView.layer addAnimation:transition forKey:@"transition"];
        }];
        
    }];
    

    [Team9Tool imageView:self.faceImageView type:@"0" Id:_homeModel.author_id viewController:self.vc baiHiden:YES];

    [Team9Tool sd_progress_imageView:self.coverImageView image:_homeModel.cover_pic placeholderImage:@"111"];
    
//    [self.coverImageView sd_setImageWithURL:[NSURL URLWithString:_homeModel.cover_pic] placeholderImage:[UIImage imageNamed:@"111"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
//        [UIView animateWithDuration:0.3 animations:^{
//            CATransition *transition = [CATransition animation];
//            transition.type = @"fade";
//            [transition setDuration:0.5];
//            [transition setRepeatCount:1];
//            // 向imageView上添加动画效果
//            [self.faceImageView.layer addAnimation:transition forKey:@"transition"];
//        }];
//        
//    }];

    
    self.titleLabel.text = _homeModel.title;
    self.title_subLabel.text = _homeModel.title_sub;
    self.likeLabel.text = _homeModel.liked_count;

    
}




- (void)createView{
    
    self.myBackView = [[Team9BaseView alloc] init];
    [self.contentView addSubview:self.myBackView];
    self.myBackView.layer.cornerRadius = 5 / 375.0 * WIDTH;
    self.myBackView.layer.masksToBounds = YES;
    
    self.coverImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.coverImageView];

    
    self.faceImageView = [UIImageView new];
    [self.contentView addSubview:self.faceImageView];
    self.faceImageView.layer.cornerRadius = 20 * WIDTH /375;
    self.faceImageView.layer.masksToBounds = YES;

    
    self.likeImageView = [UIImageView new];
    [self.contentView addSubview:self.likeImageView];
    
    self.titleLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeOrangeGreen];
    [self.contentView addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont systemFontOfSize:15 / 375.0 * WIDTH];
   
    
    
    self.title_subLabel = [[Team9BaseLabel alloc] init];
    [self.contentView addSubview:self.title_subLabel];
    self.title_subLabel.font = [UIFont systemFontOfSize:13 / 375.0 * WIDTH];
   

    
    self.likeLabel = [[Team9BaseLabel alloc] init];
    [self.contentView addSubview:self.likeLabel];
    self.likeLabel.font = [UIFont systemFontOfSize:10 / 375.0 * WIDTH];
    self.likeLabel.textAlignment = NSTextAlignmentCenter;
   
    
//    self.contentView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    
    
    
    
    
    
    [self h_contrains];
  
  }


- (void)h_contrains{
    [self.myBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10 / 375.0 * WIDTH, 10 / 375.0 * WIDTH, 10 / 375.0 * WIDTH, 10 / 375.0 * WIDTH));
    }];
    
    [self.coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.equalTo(self.myBackView);
        make.height.equalTo(self.coverImageView.mas_width).multipliedBy(0.6);
    }];
    
    [self.faceImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.coverImageView.mas_bottom).offset(10 / 375.0 * WIDTH);
        make.left.equalTo(self.myBackView).offset(10 / 375.0 * WIDTH);
        make.height.equalTo(@(40 * WIDTH / 375));
        make.width.equalTo(self.faceImageView.mas_height);
    }];
    
    [self.likeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.faceImageView);
        make.height.width.equalTo(self.faceImageView).multipliedBy(0.5);
        make.right.equalTo(self.myBackView).offset(-10 / 375.0 * WIDTH);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.faceImageView);
        make.left.equalTo(self.faceImageView.mas_right).offset(10 / 375.0 * WIDTH);
        make.right.equalTo(self.likeImageView.mas_left).offset(-10 / 375.0 * WIDTH);
    }];
    
    [self.title_subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.faceImageView);
        make.left.equalTo(self.faceImageView.mas_right).offset(10 / 375.0 * WIDTH);
        make.right.equalTo(self.likeImageView.mas_left).offset(-10 / 375.0 * WIDTH);
    }];
    
    [self.likeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.equalTo(self.likeImageView);
        make.bottom.equalTo(self.faceImageView);
    }];
}



- (void)layoutSubviews
{
    [super layoutSubviews];

}


@end
